<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>group manage</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script src="<%=basePath%>js/jquery-1.7.1.min.js" type="text/javascript"></script>   

	<link rel="stylesheet" href="<%=basePath%>css/jquery-ui-1.8.2.custom.css" type="text/css"></link>
	<link rel="stylesheet" href="<%=basePath%>css/ui.jqgrid.css" type="text/css"></link>
	<!-- 语音包必需在jqgrid之前，否则报undefined错误 -->
	<script type="text/javascript" src="<%=basePath%>js/i18n/grid.locale-cn.js"></script>
	
	<script type="text/javascript" src="<%=basePath%>js/jquery.jqGrid.min.js"></script>
	
	<style type="text/css">
	html, body,div,td {  
	   margin: 0;  
	    padding: 0;  
	    font-size:12px;  
	}  

	</style>
	
<script type="text/javascript">
	$(function() {
		// 配置jqGrid组件  
		$("#gridTable").jqGrid({
			url : "admin/group!list.action",
			datatype : "json",
			colNames : ['ID', '组名称','组信息', '创建日期','创建者' ],
			mtype : "GET",
			height : 440,
			autowidth : true,
			colModel : [ {name:"id",index:"id",width:50,sortable:true,searchoptions:{sopt:["eq","ne","lt","le","gt","ge"]}},
			             {name : "groupname",index : "groupname",width : 80,sortable : true,searchoptions:{sopt:["eq","ne","lt","le","gt","ge"]}}, 
			             {name : "groupinfo",index : "groupinfo",width : 80,sortable : false,search:false},
			             {name : "createdate",index : "createdate",formatter:"date",formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},width : 80,sortable : true,searchoptions:{sopt:["eq","ne","lt","le","gt","ge"]}},
			             {name : "mastername",index : "mastername",width : 80,sortable : false,search:false}
			             ],
			viewrecords : true,
			rowNum : 15,
			rowList : [ 15, 50, 100 ],
			prmNames : {search : "search"}, //(1)  
			jsonReader : {
				root : "gridModel", // (2)  
				records : "record", // (3)  
				repeatitems : false// (4)  
			},
			pager : "#gridPager",
			caption : "用户组列表",
			hidegrid : false,
			sortname:'id',
			sortorder: "asc"
		});
	});

	//单条件查询
	
	var singleSearch = function() {
		$("#gridTable").jqGrid("searchGrid", {
			caption : "查找",
			Find : "Go!",
			closeAfterSearch : true
		});
	};
	//删除
	var deleteObj = function() {
		var id = $("#gridTable").jqGrid("getGridParam", "selrow");
		if(id == null || id == ""){
			alert("没有选中任何记录！");
			return;
		}
		var params = {"id" : id}; 
		var actionUrl = "admin/group!delete.action";
		if(window.confirm('确定要删除吗？')){
			$.ajax({
				url : actionUrl,
				data : params,
				dataType : "text",
				cache : false,
				error : function(textStatus, errorThrown) {
					alert("系统ajax交互错误: " + textStatus);
				},
				success : function(data, textStatus) {
					if (data == "ajax_ok") {
						$("#gridTable").jqGrid("delRowData", id);
						alert("删除成功!");
					} else {
						alert("删除操作失败!");
					}
				}
			});
		}

	};
	
	//刷新
	var reload = function(){
		var url = "admin/group!list.action";
		$("#gridTable").jqGrid('setGridParam',{url:url,search:false}).trigger("reloadGrid");
	};
	
	//新增
	var newObj = function(){
		window.location="<%=basePath %>/admin/group!addOrUpdate.action";
	};
	//编辑
	var editObj = function(){
		var id = $("#gridTable").jqGrid("getGridParam", "selrow");
		if(id == null || id == ""){
			alert("没有选中任何记录！");
			return;
		}
		
		window.location="<%=basePath %>/admin/group!addOrUpdate.action?id=" + id.trim();
	}
</script>
  </head>
  
  <body>
	<div>
		<input type="button" value="新增" onclick="newObj()" />
		<input type="button" value="编辑" onclick="editObj()" />
		<input type="button" value="删除" onclick="deleteObj()" />
		<input type="button" value="单条件查询" onclick="singleSearch()" />
		<input type="button" value="刷新" onclick="reload()" />
		<input type="button" value="导出excel" onclick="singleSearch()" />
		
	</div>
	<div>
		<table id="gridTable"></table>
		<div id="gridPager"></div>
	</div>
	

</body>

</html>
